<?php
/**
 * @package Curly
 * @version 0.9
 * @link http://curly.codeplex.com/
 * @license http://curly.codeplex.com/license The MIT License
 * @author Dawid Zawada
 */

namespace Curly
{
    use Curly\Event\Event;

    /**
     * Event that fires when HTTP request finishes or fails
     * 
     * @package Curly
     * @license http://curly.codeplex.com/license The MIT License
     */
	class RequestCompletedEvent extends Event
    {
        /**
         * HttpClient object that fired this event
         * 
         * @var Curly\HttpClient
         */
        protected $client;
        
        /**
         * Request object
         * 
         * @var Curly\Request
         */
        protected $request;
        
        /**
         * Response object
         * 
         * @var Curly\Response
         */
        protected $response;
        
        /**
         * Returns the HttpClient object that fired this event
         *
         * @return Curly\HttpClient
         */
        public function getClient()
        {
            return $this->client;
        }
        
        /**
         * Sets the HttpClient object that fired this event
         * 
         * @param Curly\HttpClient $client
         */
        protected function setClient( HttpClient $client )
        {
            $this->client = $client;
        }
        
        /**
         * Returns the Request object
         *
         * @return Curly\Request
         */
        public function getRequest()
        {
            return $this->request;
        }
        
        /**
         * Sets the Request object
         * 
         * @param Curly\Request $request
         */
        protected function setRequest( Request $request )
        {
            $this->request = $request;
        }
        
        /**
         * Returns the response object
         *
         * @return Curly\Response
         */
        public function getResponse()
        {
            return $this->response;
        }
        
        /**
         * Sets the Response object
         * 
         * @param Curly\Response $response
         */
        protected function setResponse( Response $response )
        {
            $this->response = $response;
        }
        
        /**
         * Sets the HttpClient, Request and Response objects and fires the event
         * 
         * @internal
         * @param Curly\HttpClient $client
         * @param Curly\Request $request
         * @param Curly\Response $response
         */
        public function __invoke( HttpClient $client, Request $request, Response $response )
        {
            $this->setClient( $client );
            $this->setRequest( $request );
            $this->setResponse( $response );
            
            $this->notify();
        }
    }
}